package com.cee.admin.modules.cc.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cee.common.core.query.BasePageQuery;
import com.cee.common.utils.StringUtils;
import com.cee.common.web.result.Result;
import com.cee.common.core.vo.SimpleSelectionBox;
import com.cee.domain.modules.cc.entity.CcEmissionSourceOrigin;
import com.cee.domain.modules.cc.form.add.CcEmissionSourceOriginAddForm;
import com.cee.domain.modules.cc.form.update.CcEmissionSourceOriginUpdateForm;
import com.cee.ds.common.constants.PermissionConstants;
import com.cee.ds.modules.cc.service.ICcEmissionSourceOriginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cee.admin.common.BaseController;

import javax.validation.Valid;import java.util.List;

/**
 * <p>
 * 排放源源流 前端控制器
 * </p>
 *
 * @author autoGenerator
 * @since 2023-12-22
 */
@RestController
@RequestMapping("/api/v1/carbonComponent/carbonEmissionSourceOrigin")
@Tag(name = "碳组件—排放源-源流")
public class CcEmissionSourceOriginController extends BaseController {

    @Autowired
    private ICcEmissionSourceOriginService emissionSourceOriginService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @RequiresPermissions(PermissionConstants.CC_EMISSIONS_ORIGIN_PREFIX + PermissionConstants.READ)
    public Result<Page<CcEmissionSourceOrigin>> page(BasePageQuery<CcEmissionSourceOrigin> query, String name) {
        return success(emissionSourceOriginService.page(query.generatePage(), emissionSourceOriginService.lambdaQueryWrapper().like(StringUtils.isNotBlank(name), CcEmissionSourceOrigin::getName, name)));
    }

    @GetMapping("/selectionBox")
    @Operation(summary = "获取搜索框数据")
    public Result<List<SimpleSelectionBox>> selectionBox() {
        return success(emissionSourceOriginService.selectionBox());
    }

    @PostMapping("/add")
    @Operation(summary = "添加")
    @RequiresPermissions(PermissionConstants.CC_EMISSIONS_ORIGIN_PREFIX + PermissionConstants.ADD)
    public Result<Boolean> add(@Valid @RequestBody CcEmissionSourceOriginAddForm addForm) {
        return success(emissionSourceOriginService.save(addForm.toEntity()));
    }

    @PostMapping("/update")
    @Operation(summary = "更新")
    @RequiresPermissions(PermissionConstants.CC_EMISSIONS_ORIGIN_PREFIX + PermissionConstants.UPDATE)
    public Result<Boolean> update(@Valid @RequestBody CcEmissionSourceOriginUpdateForm updateForm) {
        return success(emissionSourceOriginService.updateById(updateForm.toEntity()));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除")
    @RequiresPermissions(PermissionConstants.CC_EMISSIONS_ORIGIN_PREFIX + PermissionConstants.DEL)
    public Result<Boolean> delete(@PathVariable("id") Integer id)  {
        return success(emissionSourceOriginService.removeById(id));
    }
}

